package config

import (
	"gitee.com/llakcs/gnetty/commom"
	"time"
)

//通道设置
type ServerConfig struct {
	Port            string                       //监听端口
	ReadTimeout     time.Duration                //服务端读取不到数据超时时间
	BufferSize      int                          //缓冲区大小
	ChanSize        int                          //队列大小
	Enable          bool                         //是否开启
	ChanReadHandler commom.ChannelInboundHandler //业务处理器
	DecoderHandler  commom.DecodeHandler         //自定义解码处理
	EncodeHandler   commom.EncodeHandler         //自定义编码器
}

func ServerConfigBuild() *ServerConfig {
	return &ServerConfig{
		Port:            "",
		ReadTimeout:     0,
		BufferSize:      0,
		ChanSize:        0,
		Enable:          true,
		ChanReadHandler: nil,
		DecoderHandler:  nil,
		EncodeHandler:   nil,
	}
}

func (c *ServerConfig) WithPort(port string) *ServerConfig {
	c.Port = port
	return c
}

func (c *ServerConfig) WithReadTimeOut(out time.Duration) *ServerConfig {
	c.ReadTimeout = out
	return c
}

//设置接收缓冲区大小
func (c *ServerConfig) WithBufferSize(bufsize int) *ServerConfig {
	c.BufferSize = bufsize
	return c
}

//设置通道队列大小
func (c *ServerConfig) WithChanSize(chansize int) *ServerConfig {
	c.ChanSize = chansize
	return c
}

//启用或禁用这项设置
func (c *ServerConfig) WithEnale(enable bool) *ServerConfig {
	c.Enable = enable
	return c
}

//设置业务处理器
func (c *ServerConfig) WithChanReadHandler(ch commom.ChannelInboundHandler) *ServerConfig {
	c.ChanReadHandler = ch
	return c
}

//设置解码处理器
func (c *ServerConfig) WithDecodeHandler(d commom.DecodeHandler) *ServerConfig {
	c.DecoderHandler = d
	return c
}

//设置编码处理器
func (c *ServerConfig) WithEncodeHandler(e commom.EncodeHandler) *ServerConfig {
	c.EncodeHandler = e
	return c
}
